{% extends 'base.html' %}
{% load static %}

{% block title %}{{ worldcup.name }} - 特色排行榜 - Creeps Judge{% endblock %}

{% block extra_css %}
<link href="{% static 'css/worldcup.css' %}" rel="stylesheet">
<style>
    .container {
        background: transparent;
        backdrop-filter: none;
        border-radius: 0;
        padding: 0;
        margin-top: 20px;
        margin-bottom: 20px;
        box-shadow: none;
        border: none;
        color: rgba(255, 255, 255, 0.9);
    }

    .special-rankings-header {
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(30, 30, 60, 0.9) 100%);
        backdrop-filter: blur(15px);
        border-radius: 20px;
        border: 2px solid rgba(255, 215, 0, 0.5);
        padding: 20px;
        margin-bottom: 25px;
        text-align: center;
        box-shadow:
            0 8px 32px rgba(0, 0, 0, 0.3),
            0 0 20px rgba(255, 215, 0, 0.2),
            inset 0 0 15px rgba(255, 255, 255, 0.05);
    }

    .special-rankings-title {
        font-size: 2.5rem;
        font-weight: 800;
        color: #FFD700;
        margin: 0 0 10px;
        text-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    }

    .special-rankings-subtitle {
        font-size: 1.2rem;
        color: rgba(255, 255, 255, 0.8);
        margin: 0;
    }

    .tabs-container {
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(30, 30, 60, 0.9) 100%);
        backdrop-filter: blur(15px);
        border-radius: 20px;
        border: 2px solid rgba(255, 215, 0, 0.3);
        padding: 0;
        margin-bottom: 25px;
        overflow: hidden;
        box-shadow:
            0 8px 32px rgba(0, 0, 0, 0.3),
            0 0 20px rgba(255, 215, 0, 0.2),
            inset 0 0 15px rgba(255, 255, 255, 0.05);
    }

    .tabs-nav {
        display: flex;
        background: rgba(0, 0, 0, 0.3);
        border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    }

    .tab-button {
        flex: 1;
        padding: 15px 20px;
        background: transparent;
        border: none;
        color: rgba(255, 255, 255, 0.7);
        font-size: 1.1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
        border-right: 1px solid rgba(255, 215, 0, 0.2);
    }

    .tab-button:last-child {
        border-right: none;
    }

    .tab-button:hover {
        background: rgba(255, 215, 0, 0.1);
        color: rgba(255, 255, 255, 0.9);
    }

    .tab-button.active {
        background: linear-gradient(135deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 165, 0, 0.2) 100%);
        color: #FFD700;
        border-bottom: 3px solid #FFD700;
    }

    .tab-content {
        display: none;
        padding: 25px;
    }

    .tab-content.active {
        display: block;
    }

    .ranking-table {
        width: 100%;
        border-collapse: collapse;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        overflow: hidden;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }

    .ranking-table thead {
        background: linear-gradient(135deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 165, 0, 0.2) 100%);
    }

    .ranking-table th {
        padding: 15px 20px;
        text-align: center;
        font-weight: 700;
        color: #FFD700;
        font-size: 1.1rem;
        border-bottom: 2px solid rgba(255, 215, 0, 0.3);
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    }

    .ranking-table tbody tr {
        transition: all 0.3s ease;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .ranking-table tbody tr:nth-child(even) {
        background: rgba(255, 255, 255, 0.02);
    }

    .ranking-table tbody tr:hover {
        background: rgba(255, 215, 0, 0.1);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(255, 215, 0, 0.2);
    }

    .ranking-table tbody tr.top-3 {
        background: rgba(255, 215, 0, 0.1);
        border-left: 4px solid #FFD700;
    }

    .ranking-table tbody tr.top-3:hover {
        background: rgba(255, 215, 0, 0.15);
    }

    .ranking-table td {
        padding: 15px 20px;
        text-align: center;
        color: rgba(255, 255, 255, 0.9);
        font-size: 1rem;
        vertical-align: middle;
    }

    .rank-cell {
        font-weight: bold;
        font-size: 1.2rem;
    }

    .rank-1 { color: #FFD700; }
    .rank-2 { color: #C0C0C0; }
    .rank-3 { color: #CD7F32; }

    .player-name {
        font-weight: 600;
        color: #FFD700;
    }

    .stat-value {
        font-weight: 700;
        font-size: 1.1rem;
    }

    .healing-value { color: #00FF7F; }
    .death-value { color: #FF6B6B; }
    .destroyed-value { color: #FF4500; }

    .matches-count {
        color: rgba(255, 255, 255, 0.7);
        font-size: 0.9rem;
    }

    .no-data {
        text-align: center;
        padding: 40px;
        color: rgba(255, 255, 255, 0.6);
        font-size: 1.1rem;
    }

    .back-button {
        display: inline-block;
        padding: 12px 24px;
        background: linear-gradient(135deg, rgba(255, 215, 0, 0.2) 0%, rgba(255, 165, 0, 0.2) 100%);
        color: #FFD700;
        text-decoration: none;
        border-radius: 10px;
        border: 1px solid rgba(255, 215, 0, 0.5);
        font-weight: 600;
        transition: all 0.3s ease;
        margin-bottom: 20px;
    }

    .back-button:hover {
        background: linear-gradient(135deg, rgba(255, 215, 0, 0.3) 0%, rgba(255, 165, 0, 0.3) 100%);
        border-color: rgba(255, 215, 0, 0.8);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
        color: #FFD700;
        text-decoration: none;
    }

    .ranking-icon {
        margin-right: 8px;
        font-size: 1.2rem;
    }

    .tab-icon {
        margin-right: 8px;
        font-size: 1.1rem;
    }

    /* 响应式设计 */
    @media (max-width: 768px) {
        .special-rankings-title {
            font-size: 2rem;
        }

        .tab-button {
            padding: 12px 15px;
            font-size: 1rem;
        }

        .ranking-table th,
        .ranking-table td {
            padding: 10px 12px;
            font-size: 0.9rem;
        }

        .rank-cell {
            font-size: 1rem;
        }

        .stat-value {
            font-size: 1rem;
        }
    }

    @media (max-width: 480px) {
        .tabs-nav {
            flex-direction: column;
        }

        .tab-button {
            border-right: none;
            border-bottom: 1px solid rgba(255, 215, 0, 0.2);
        }

        .tab-button:last-child {
            border-bottom: none;
        }

        .ranking-table {
            font-size: 0.8rem;
        }

        .ranking-table th,
        .ranking-table td {
            padding: 8px 10px;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="container">
    <a href="{% url 'battles:worldcup_detail' worldcup.id %}" class="back-button">
        <i class="fas fa-arrow-left"></i> 返回世界杯详情
    </a>

    <div class="special-rankings-header">
        <h1 class="special-rankings-title">
            <i class="fas fa-trophy"></i> {{ worldcup.name }}
        </h1>
        <p class="special-rankings-subtitle">特色排行榜 - 常规赛数据统计</p>
    </div>

    <div class="tabs-container">
        <div class="tabs-nav">
            <button class="tab-button active" onclick="switchTab('healing')" id="healing-tab">
                <i class="fas fa-heart tab-icon"></i>最强奶妈榜
            </button>
            <button class="tab-button" onclick="switchTab('deaths')" id="deaths-tab">
                <i class="fas fa-skull tab-icon"></i>老弱病残榜
            </button>
            <button class="tab-button" onclick="switchTab('destroyed')" id="destroyed-tab">
                <i class="fas fa-bomb tab-icon"></i>无家可归榜
            </button>
        </div>

        <!-- 治疗榜 -->
        <div id="healing-content" class="tab-content active">
            {% if healing_rankings %}
            <table class="ranking-table">
                <thead>
                    <tr>
                        <th><i class="fas fa-medal ranking-icon"></i>排名</th>
                        <th><i class="fas fa-user ranking-icon"></i>玩家</th>
                        <th><i class="fas fa-heart ranking-icon"></i>总治疗量</th>
                        <th><i class="fas fa-gamepad ranking-icon"></i>常规赛场次</th>
                        <th><i class="fas fa-chart-line ranking-icon"></i>平均治疗</th>
                    </tr>
                </thead>
                <tbody>
                    {% for ranking in healing_rankings %}
                    <tr {% if forloop.counter <= 3 %}class="top-3"{% endif %}>
                        <td class="rank-cell rank-{{ forloop.counter }}">
                            {% if forloop.counter == 1 %}
                                🥇 {{ forloop.counter }}
                            {% elif forloop.counter == 2 %}
                                🥈 {{ forloop.counter }}
                            {% elif forloop.counter == 3 %}
                                🥉 {{ forloop.counter }}
                            {% else %}
                                {{ forloop.counter }}
                            {% endif %}
                        </td>
                        <td class="player-name">{{ ranking.participant.user.username }}</td>
                        <td class="stat-value healing-value">{{ ranking.total_healing|floatformat:0 }}</td>
                        <td class="matches-count">{{ ranking.regular_matches_played }}</td>
                        <td class="stat-value">{{ ranking.avg_healing|floatformat:1 }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="no-data">
                <i class="fas fa-heart" style="font-size: 3rem; margin-bottom: 20px; opacity: 0.5;"></i>
                <p>暂无治疗数据</p>
            </div>
            {% endif %}
        </div>

        <!-- 死亡榜 -->
        <div id="deaths-content" class="tab-content">
            {% if death_rankings %}
            <table class="ranking-table">
                <thead>
                    <tr>
                        <th><i class="fas fa-medal ranking-icon"></i>排名</th>
                        <th><i class="fas fa-user ranking-icon"></i>玩家</th>
                        <th><i class="fas fa-skull ranking-icon"></i>总死亡数</th>
                        <th><i class="fas fa-gamepad ranking-icon"></i>常规赛场次</th>
                        <th><i class="fas fa-chart-line ranking-icon"></i>平均死亡</th>
                    </tr>
                </thead>
                <tbody>
                    {% for ranking in death_rankings %}
                    <tr {% if forloop.counter <= 3 %}class="top-3"{% endif %}>
                        <td class="rank-cell rank-{{ forloop.counter }}">
                            {% if forloop.counter == 1 %}
                                🥇 {{ forloop.counter }}
                            {% elif forloop.counter == 2 %}
                                🥈 {{ forloop.counter }}
                            {% elif forloop.counter == 3 %}
                                🥉 {{ forloop.counter }}
                            {% else %}
                                {{ forloop.counter }}
                            {% endif %}
                        </td>
                        <td class="player-name">{{ ranking.participant.user.username }}</td>
                        <td class="stat-value death-value">{{ ranking.total_deaths|floatformat:0 }}</td>
                        <td class="matches-count">{{ ranking.regular_matches_played }}</td>
                        <td class="stat-value">{{ ranking.avg_deaths|floatformat:1 }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="no-data">
                <i class="fas fa-skull" style="font-size: 3rem; margin-bottom: 20px; opacity: 0.5;"></i>
                <p>暂无死亡数据</p>
            </div>
            {% endif %}
        </div>

        <!-- 基地被毁榜 -->
        <div id="destroyed-content" class="tab-content">
            {% if destroyed_rankings %}
            <table class="ranking-table">
                <thead>
                    <tr>
                        <th><i class="fas fa-medal ranking-icon"></i>排名</th>
                        <th><i class="fas fa-user ranking-icon"></i>玩家</th>
                        <th><i class="fas fa-bomb ranking-icon"></i>基地被毁次数</th>
                        <th><i class="fas fa-gamepad ranking-icon"></i>常规赛场次</th>
                        <th><i class="fas fa-chart-line ranking-icon"></i>被毁率</th>
                    </tr>
                </thead>
                <tbody>
                    {% for ranking in destroyed_rankings %}
                    <tr {% if forloop.counter <= 3 %}class="top-3"{% endif %}>
                        <td class="rank-cell rank-{{ forloop.counter }}">
                            {% if forloop.counter == 1 %}
                                🥇 {{ forloop.counter }}
                            {% elif forloop.counter == 2 %}
                                🥈 {{ forloop.counter }}
                            {% elif forloop.counter == 3 %}
                                🥉 {{ forloop.counter }}
                            {% else %}
                                {{ forloop.counter }}
                            {% endif %}
                        </td>
                        <td class="player-name">{{ ranking.participant.user.username }}</td>
                        <td class="stat-value destroyed-value">{{ ranking.base_destroyed_count|floatformat:0 }}</td>
                        <td class="matches-count">{{ ranking.regular_matches_played }}</td>
                        <td class="stat-value">{{ ranking.destroyed_rate|floatformat:1 }}%</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="no-data">
                <i class="fas fa-bomb" style="font-size: 3rem; margin-bottom: 20px; opacity: 0.5;"></i>
                <p>暂无基地被毁数据</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>

<script>
function switchTab(tabName) {
    // 隐藏所有标签页内容
    const allContents = document.querySelectorAll('.tab-content');
    allContents.forEach(content => {
        content.classList.remove('active');
    });

    // 移除所有按钮的活动状态
    const allButtons = document.querySelectorAll('.tab-button');
    allButtons.forEach(button => {
        button.classList.remove('active');
    });

    // 显示选中的标签页内容
    document.getElementById(tabName + '-content').classList.add('active');

    // 激活选中的按钮
    document.getElementById(tabName + '-tab').classList.add('active');
}

// 页面加载完成后的初始化
document.addEventListener('DOMContentLoaded', function() {
    // 默认显示治疗榜
    switchTab('healing');
});
</script>
{% endblock %}